<?=$this->header(true)?>


    <?=$this->menu("downloads")?>


    <h1><?=$this->message("label.header", _Download::BUNDLE)?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.category.header", _Download::BUNDLE),
                "href"=>"download/category/list"
            ),
            array(
                "name"=>$this->category($this->downloadForm->getRevision()->getDownload()->getCategoryId()),
                "href"=>"download/list"
            ),
            array(
                "name"=>($this->downloadForm->getRevision()->getDownloadRevisionId() > 0 ?
                    $this->message("route.edit", _Core::BUNDLE) . " " .
                        "\"".$this->downloadForm->getRevision()->getBinaryFile()->getFileName()."\" " :
                    $this->message("route.new", _Core::BUNDLE) . " " . $this->message("label.item", _Download::BUNDLE))
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Download::BUNDLE)?>


    <form id="<?=get_class($this->downloadForm)?>" action="download/save" method="post" enctype="multipart/form-data">

        <div>
            <input type="hidden"
                   name="revision->downloadRevisionId"
                   value="<?=$this->downloadForm->getRevision()->getDownloadRevisionId()?>" />
            <input type="hidden"
                   name="revision->downloadId"
                   value="<?=$this->downloadForm->getRevision()->getDownloadId()?>" />
            <input type="hidden"
                   name="revision->binaryFileId"
                   value="<?=$this->downloadForm->getRevision()->getBinaryFileId()?>" />
            <input type="hidden"
                   name="revision->download->categoryId"
                   value="<?=$this->downloadForm->getRevision()->getDownload()->getCategoryId()?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.required", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("revision->download->description")?>">
                <th><label for="revision_download_description"><?=$this->message("prompt.description", _Download::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="revision->download->description"
                           id="download_description"
                           value="<?=$this->downloadForm->getRevision()->getDownload()->getDescription()?>"
                           maxlength="32"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("formFile")?>">
                <th><label for="formFile"><?=$this->message("prompt.file", _Download::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="formFile"
                           id="formFile"
                           value=""
                           maxlength="32"
                           type="file"
                           class="textInput" />
                    <br />
                    <input name="overwrite"
                           id="overwrite"
                           value="true"
                           type="hidden"/>
                </td>
            </tr>
            </table>

        </fieldset>

        <fieldset>

            <legend><?=$this->message("label.optional", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("revision->download->publicationDate")?>">
                <th><?=$this->message("prompt.publication", _Download::BUNDLE)?><p class="hint">(<label for="publicationDay"><?=$this->message("prompt.day", _Download::BUNDLE)?></label>/<label for="publicationMonth"><?=$this->message("prompt.month", _Download::BUNDLE)?></label>/<label for="publicationYear"><?=$this->message("prompt.year", _Download::BUNDLE)?></label>)</p></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <?=$this->formDays(
                        "publicationDay",
                        $this->downloadForm->getPublicationDay()
                    )?>
                    <?=$this->formMonths(
                        "publicationMonth",
                        $this->downloadForm->getPublicationMonth()
                    )?>
                    <?=$this->formYears(
                        "publicationYear",
                        $this->downloadForm->getPublicationYear()
                    )?>
                </td>
            </tr>
            <!--tr class="ctrl<?=$this->error("formImage")?>">
                <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <? if(!is_null($this->downloadForm->getRevision()->getDownload()) &&
                        $this->downloadForm->getRevision()->getDownload()->getImageId() > 0 &&
                        !is_null($this->downloadForm->getRevision()->getDownload()->getImageRelatedByImageId())) { ?>

                        <input type="hidden"
                               name="revision->download->imageRelatedByImageId->imageId"
                               value="<?=$this->downloadForm->getRevision()->getDownload()->getImageId()?>" />
                        <input type="hidden"
                               name="revision->download->imageRelatedByThumbnailId->imageId"
                               value="<?=$this->downloadForm->getRevision()->getDownload()->getThumbnailId()?>" />

                        <input type="hidden"
                               name="revision->download->imageRelatedByImageId->binaryFileId"
                               value="<?=$this->downloadForm->getRevision()->getDownload()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                        <input type="hidden"
                               name="revision->download->imageRelatedByThumbnailId->binaryFileId"
                               value="<?=$this->downloadForm->getRevision()->getDownload()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                        <img src="image?id=<?=$this->downloadForm->getRevision()->getDownload()->getImageId()?>"
                             width="<?=$this->downloadForm->getRevision()->getDownload()->getImageRelatedByImageId()->getWidth()?>"
                             height="<?=$this->downloadForm->getRevision()->getDownload()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                        <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>

                        <br /><br />

                    <? } ?>

                    <input type="file" name="formImage" />

                    <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_LIST))->getImageWidth()?>x<?=$this->imageProps($this->param(_CORE::SETTING_LIST))->getImageHeight()?>.</p>

                </td>
            </tr-->

            <? /* Only show revision note textarea when editing existing download */ ?>
            <? /* if($this->downloadForm->getRevision()->getDownloadRevisionId() > 0): ?>

                <tr class="ctrl<?=$this->error("revision->description")?>">
                    <th><label for="revision_description"><?=$this->message("prompt.message", _Download::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <textarea name="revision->description"
                                  id="revision_description"
                                  class="textInput"
                                  style="height:80px"><?=$this->downloadForm->getRevision()->getDescription()?></textarea>
                    </td>
                </tr>

            <? endif; */?>

            </table>

        </fieldset>

        <div class="buttons">

            <input type="button"
                   onclick="to('download/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>